<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>发表新帖</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="fly,layui,前端社区">
    <meta name="description" content="Fly社区是模块化前端UI框架Layui的官网社区，致力于为web开发提供强劲动力">
    <link rel="stylesheet" href="../../res/layui/css/layui.css">
    <link rel="stylesheet" href="../../res/css/global.css">
</head>
<body>

<div class="fly-header layui-bg-black">
    <div class="layui-container">
        <a class="fly-logo" href="../jie/index.html">
            <img src="../../res/images/logo.png" alt="layui">
        </a>
        <ul class="layui-nav fly-nav layui-hide-xs">
            <li class="layui-nav-item layui-this">
                <a href="/"><i class="iconfont icon-jiaoliu"></i>交流</a>
            </li>
            <li class="layui-nav-item">
                <a href="../case/case.html"><i class="iconfont icon-iconmingxinganli"></i>案例</a>
            </li>
            <li class="layui-nav-item">
                <a href="http://www.layui.com/" target="_blank"><i class="iconfont icon-ui"></i>框架</a>
            </li>
        </ul>

        <div id="user_view">
            <ul class="layui-nav fly-nav-user">
                <!-- 未登入的状态 -->
                <li class="layui-nav-item">
                    <a class="iconfont icon-touxiang layui-hide-xs" href="../user/login.html"></a>
                </li>
                <li class="layui-nav-item">
                    <a href="../user/login.html">登入</a>
                </li>
                <li class="layui-nav-item">
                    <a href="../user/reg.html">注册</a>
                </li>
            </ul>
        </div>
    </div>
</div>

<div class="layui-container fly-marginTop">
    <div class="fly-panel" pad20 style="padding-top: 5px;">
        <!--<div class="fly-none">没有权限</div>-->
        <div class="layui-form layui-form-pane">
            <div class="layui-tab layui-tab-brief">
                <ul class="layui-tab-title">
                    <li class="layui-this">发表新帖<!-- 编辑帖子 --></li>
                </ul>
                <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                    <div class="layui-tab-item layui-show">
                        <form>
                            <div class="layui-row layui-col-space15 layui-form-item">
                                <div class="layui-col-md3">
                                    <label class="layui-form-label">所在专栏</label>
                                    <div class="layui-input-block">
                                        <select name="newstype">
                                            <option value="0">提问</option>
                                            <option value="1">分享</option>
                                            <option value="2">讨论</option>
                                            <option value="3">建议</option>
                                            <option value="4">公告</option>
                                            <option value="5">动态</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-col-md9">
                                    <label for="L_title" class="layui-form-label">标题</label>
                                    <div class="layui-input-block">
                                        <input type="text" id="L_title" name="title" required lay-verify="required"
                                               autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <div class="layui-input-block">
                                    <textarea id="L_content" name="content"
                                              placeholder="详细描述" class="layui-textarea"
                                              style="height: 260px;"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <button type="button" class="layui-btn" lay-filter="add_news_btn" lay-submit>立即发布
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="fly-footer">
    <p><a href="http://fly.layui.com/" target="_blank">Fly社区</a> 2017 &copy; <a href="http://www.layui.com/"
                                                                                target="_blank">layui.com 出品</a></p>
    <p>
        <a href="http://fly.layui.com/jie/3147/" target="_blank">付费计划</a>
        <a href="http://www.layui.com/template/fly/" target="_blank">获取Fly社区模版</a>
        <a href="http://fly.layui.com/jie/2461/" target="_blank">微信公众号</a>
    </p>
</div>
<script src="../../res/layui/layui.js"></script>
<script type="text/javascript" src="../../res/jquery-1.7.2.min.js"></script>
<script id="user_tmp" type="text/html">

    <ul class="layui-nav fly-nav-user">
        <li class="layui-nav-item">
            <a class="fly-nav-avatar" href="javascript:;">
                <cite class="layui-hide-xs">{{d.username}}</cite>
                <i class="iconfont icon-renzheng layui-hide-xs" title="认证信息：layui 作者"></i>
                <i class="layui-badge fly-badge-vip layui-hide-xs">VIP</i>
                <img src="{{d.headurl}}">
            </a>
            <dl class="layui-nav-child">
                <dd><a href="../user/set.html"><i class="layui-icon">&#xe620;</i>基本设置</a></dd>
                <dd><a href="../user/message.html"><i class="iconfont icon-tongzhi" style="top: 4px;"></i>我的消息</a>
                </dd>
                <dd><a href="../user/home.html"><i class="layui-icon" style="margin-left: 2px; font-size: 22px;">&#xe68e;</i>我的主页</a>
                </dd>
                <hr style="margin: 5px 0;">
                <dd><a onclick="logout()" style="text-align: center;">退出</a></dd>
            </dl>
        </li>
    </ul>
</script>
<script>

    $(function () {
        user_info();
        text_area_show();
    })

    function user_info() {
        $.ajax(address + '/login/getUserInfoByTicket', {
            type: 'POST',
            dataType: 'json'
        }).done(function (data) {
            console.log("执行当前函数");
            //渲染
            layui.use('laytpl', function () {
                let laytpl = layui.laytpl;
                if (data.data != undefined) {
                    let user_view = document.getElementById("user_view");
                    let user_tmp = document.getElementById("user_tmp").innerHTML;
                    laytpl(user_tmp).render(data.data, function (html) {
                        user_view.innerHTML = html;
                    });
                    layui.use('element', function () {
                        let element = layui.element;
                        element.init();
                    });
                }
            })
        })
    }

    function text_area_show() {
        layui.use('layedit', function () {
            let layedit = layui.layedit;
            layedit.set({
                uploadImage: {
                    url: address + '/news/addNewsPicture',
                    type: 'POST',
                    accept: 'images',
                }
            });
            window.index = layedit.build('L_content', {}); //建立编辑器
        })
    }

    function logout() {
        $.ajax(address + '/login/logout', {
            type: 'POST',
            dataType: 'json'
        }).done(function (data) {
            window.location.reload()
        })
    }

    layui.use('form', function () {
        let form = layui.form;
        form.on('submit(add_news_btn)', function (data) {
            layui.use('layedit', function () {
                let layedit = layui.layedit;
                layedit.sync(window.index);
            });
            data.field.content = $('#L_content').val();
            if (data.field.content == '') {
                layer.msg('必填参数不能为空', {icon: 5, shift: 6});
            } else {
                let load_index = layer.load(0, {shade: [0.2, '#393D49']});
                $.ajax(address + '/news/addNews', {
                    type: 'POST',
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify(data.field),
                    dataType: 'json'
                }).done(function (data) {
                    layer.close(load_index);
                    if (data.code == '0') {
                        layer.alert(data.message, {
                            icon: 1,
                            title: "提示"
                        });
                        window.location = '../user/index.html';
                    } else {
                        layer.alert(data.message, {
                            icon: 5,
                            title: "提示"
                        });
                    }
                })
            }
        })
    })
</script>
<script>

</script>
</body>
</html>
